package com.fyl.ex;

import com.fyl.pojo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public ModelAndView runtime(RuntimeException e){
        System.out.println("e = " + e);
        //ModelAndView modelAndView = new ModelAndView("/index.jsp");
        ModelAndView modelAndView = new ModelAndView("/error1.html");
        return modelAndView;
    }

    @ExceptionHandler(IOException.class)
    @ResponseBody
    public Result io(IOException e){
        System.out.println("e = " + e);
        Result result = new Result();
        result.setCode(1);
        result.setMsg("1234");
        result.setData(123);
        return result;
    }

}
